package com.mcglib.flac.comboBox
{
	import com.mcglib.flac.DataRender;
	import com.mcglib.flac.FlacComponent;
	import com.mcglib.flac.FlacEvent;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class DefaultRendererClass extends DataRender
	{
		public var labelField:String = null;
		
		public function DefaultRendererClass(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		override public function initDataRenderer(ui:DisplayObject, component:FlacComponent):void{
			super.initDataRenderer(ui,component);
			mcUI.gotoAndStop("out");
			mcUI.mouseChildren = false;
			component.addEventListener(FlacEvent.REFRESH,update);
		}
		
		override public function set data(v:*):void{
			super.data = v;
			
			refresh();
		}
		
		override public function set selected(v:Boolean):void{
			super.selected = v;
			if(v)
				mcUI.gotoAndStop("selected");
			else{
				mcUI.gotoAndStop("out");
			}
		}
		
		override public function onMouseOver(e:MouseEvent):void{
			//trace("over");
			if(!selected){
				mcUI.gotoAndStop("over");
			}
		}
		
		override public function onMouseOut(e:MouseEvent):void{
			//trace("out");
			if(!selected){
				mcUI.gotoAndStop("out");
			}
		}
		
		override public function refresh():void{
			var tf:TextField = (ui as MovieClip).tf;
			var o:Object =  data;
			if(labelField!=null){
				o =data[labelField]
			}
			tf.text = o+"";
		}
		
		private function update(e:FlacEvent=null):void{
			labelField = e.value;
			refresh();
		}
		
	}
}